<?php
/**
 * 订单模型
 * @date    2020-01-01
 * @author  kiro
 * @email   294843009@qq.com
 * @version 1.0
 */
/**
rights Reserved, Designed By www.youyacao.com
@author:成都市一颗优雅草科技有限公司
@version 优雅草蜻蜓系统-服务端部分
注意：服务端代码在获得授权之前通过其他非官方渠道获得代码均为侵权，禁止用于商业用途，否则将承担因此带来等版权纠纷。
需要商业用途或者定制开发等可访问songshu.youyacao.com   联系QQ:2853810243 422108995 23625059584
优雅草开源代码地址：https://gitee.com/youyacao  可查阅所有开源项目



 */
namespace App\Models;

class Order extends BaseModel
{
    protected $table = 'order';

    protected $fillable = [
        'user_id',
        'goods_id',
        'price',
        'pay_type',
        'pay_order_id',
        'remark',
        'status'
    ];

    const TYPE_AMOUNT = 'AMOUNT';
    const TYPE_INTEGRAL = 'INTEGRAL';
    const TYPE_GOLD = 'GOLD';
    const TYPE_ALIPAY = 'ALIPAY';
    const TYPE_WXPAY = 'WXPAY';

    public static $type_arr = [
        self::TYPE_AMOUNT => '余额',
        self::TYPE_INTEGRAL => '积分',
        self::TYPE_GOLD => '金币',
        self::TYPE_ALIPAY => '支付宝',
        self::TYPE_WXPAY => '微信',
    ];

    const STATUS_CANCEL = '0';
    const STATUS_UNPAY = '1';
    const STATUS_PAID = '2';
    const STATUS_BACK = '3';

    public static $status_arr = [
        self::STATUS_CANCEL => '已取消',
        self::STATUS_UNPAY => '待支付',
        self::STATUS_PAID => '已支付',
        self::STATUS_BACK => '已退回',
    ];

    public static function add($user_id, $goods_id, $price, $remark = '')
    {
        $data = [];
        $data['user_id']    = $user_id;
        $data['goods_id']   = $goods_id;
        $data['price']      = $price;
        $data['remark']     = $remark;
        $data['status'] = 1;
        return self::create($data);
    }

    public static function setStatus($id, $status = 2, $pay_type = '', $pay_order_id = '')
    {
        $data = [];
        $data['status'] = $status;
        $data['pay_type']   = $pay_type;
        $data['pay_order_id'] = $pay_order_id;
        return self::where('id', $id)->update($data);
    }
}
